﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Timeline.Beans;
using Windows.ApplicationModel.Resources;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Content Dialog item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Timeline.Pages {
    public sealed partial class BbsDlg : ContentDialog {
        public BbsDlg(List<BbsApiData> data) {
            this.InitializeComponent();

            ResourceLoader resLoader = ResourceLoader.GetForCurrentView();

            data.Sort((a, b) => b.Start.CompareTo(a.Start)); // 日期降序
            RunBbsContent1.Text = data[0].Comment;
            if (data.Count > 1) {
                RunBbsDate1.Text = string.Format(resLoader.GetString("BbsDate"),
                    DateTime.Parse(data[0].Start).ToString("M"));
                RunBbsContent2.Text = data[1].Comment;
                RunBbsDate2.Text = string.Format(resLoader.GetString("BbsDate"),
                    DateTime.Parse(data[1].Start).ToString("M"));
                TextBbsContent2.Visibility = Visibility.Visible;
            } else {
                TextBbsContent2.Visibility = Visibility.Collapsed;
            }
            if (data.Count > 2) {
                RunBbsContent3.Text = data[2].Comment;
                RunBbsDate3.Text = string.Format(resLoader.GetString("BbsDate"),
                    DateTime.Parse(data[2].Start).ToString("M"));
                TextBbsContent3.Visibility = Visibility.Visible;
            } else {
                TextBbsContent3.Visibility = Visibility.Collapsed;
            }
        }
    }
}
